<?php
namespace app\common\model;

use \think\Model;
use \think\Log;
class Pages extends Model{
	
	public function checkForm($data)
    {
        $validate = validate('Pages');
        $res      = $validate->check($data);
        if (!$res) {
            return $validate->getError();
        } else {
            return false;
        }
    }
	
	public function savePages($data,$id = '', $allowField = true){
		$res = $this->checkForm($data);
        if ($res) {
            $msg['code'] = '0';
            $msg['msg']  = $res;
            return $msg;
        }
		try{
			if($id){
				$this->allowField(true)->save($data,['id'=>$id]);

			}else{
				$data['addtime'] = date('Y-m-d H:i:s', time());
				$data['adduser'] = session('u_id');
				$this->data($data);
				$this->allowField(true)->save();
			}
			$msg['code'] = '1';
			$msg['msg']  = '保存成功';
			return $msg;
		}catch(\Exception $e){
			$msg['code'] = '0';
            $msg['msg']  = '保存失败2';
            return $msg;

			
		}
		
		
		
	}
	
}